import request from '@/utils/request'

/**批量取消授权用户角色 */
export function cancelAuthBatch(data) {
  return request({
    url: `/distribution/userRoleDistr/cancelAuthBatch?roleId=${data.roleId}&userIds=${data.userIds.toString()}`,
    method: 'put',
    data
  })
}

/**取消授权用户角色 */
export function cancelAuth(data) {
  return request({
    url: `/distribution/userRoleDistr/cancelAuth`,
    method: 'put',
    data
  })
}


/**批量选择授权用户租户角色 */
export function insertUserRoleDistrs(data) {
  return request({
    url: `/distribution/userRoleDistr/insertUserRoleDistrs?roleId=${data.roleId}&userIds=${data.userIds.toString()}`,
    method: 'put',
    data
  })
}

/**根据条件分页查询已分配用户租户角色列表 */
export function allocatedDistrList(params) {
  return request({
    url: '/distribution/userRoleDistr/allocatedDistrList',
    params
  })
}

/**根据条件分页查询未分配用户租户角色列表 */
export function unAllocatedDistrList(params) {
  return request({
    url: '/distribution/userRoleDistr/unAllocatedDistrList',
    params
  })
}

/**状态修改 */
export function updateStatus(data) {
  return request({
    url: '/distribution/roleDistr/updateStatus',
    method: 'post',
    data
  })
}

/**删除租户角色信息 */
export function deleteRoleDistr(roleId) {
  return request({
    url: '/distribution/roleDistr/delete/' + roleId,
    method: 'DELETE'
  })
}

/**加载对应角色菜单列表树 */
export function roleDistrMenuTree(roleId) {
  return request({
    url: '/distribution/roleDistr/roleDistrMenuTree/' + roleId,
  })
}
/**获取租户角色信息详细信息 */
export function roleInfo(roleId) {
  return request({
    url: '/distribution/roleDistr/' + roleId,
  })
}

/**查询角色列表 */
export function listRole(params) {
  return request({
    url: '/distribution/roleDistr/list',
    params
  })
}

// 查询角色详细
export function getRole(roleId) {
  return request({
    url: '/distribution/roleDistr/' + roleId,
    method: 'get'
  })
}

/**新增租户角色 */
export function insert(data) {
  return request({
    url: '/distribution/roleDistr/insert',
    method: 'post',
    data
  })
}

/**修改租户角色 */
export function edit(data) {
  return request({
    url: '/distribution/roleDistr/edit',
    method: 'post',
    data
  })
}

// 角色数据权限
export function dataScope(data) {
  return request({
    url: '/distribution/roleDistr/dataScope',
    method: 'put',
    data
  })
}

// 角色状态修改
export function changeRoleStatus(roleId, status) {
  const data = {
    roleId,
    status
  }
  return request({
    url: '/distribution/roleDistr/changeStatus',
    method: 'put',
    data
  })
}

// 删除角色
export function delRole(roleId) {
  return request({
    url: '/distribution/roleDistr/' + roleId,
    method: 'delete'
  })
}

// 查询角色已授权用户列表
export function allocatedUserList(params) {
  return request({
    url: '/distribution/roleDistr/authUser/allocatedList',
    method: 'get',
    params
  })
}

// 查询角色未授权用户列表
export function unallocatedUserList(params) {
  return request({
    url: '/distribution/roleDistr/authUser/unallocatedList',
    method: 'get',
    params
  })
}

// 取消用户授权角色
export function authUserCancel(data) {
  return request({
    url: '/distribution/roleDistr/authUser/cancel',
    method: 'put',
    data
  })
}

// 批量取消用户授权角色
export function authUserCancelAll(data) {
  return request({
    url: '/distribution/roleDistr/authUser/cancelAll',
    method: 'put',
    params: data
  })
}

// 授权用户选择
export function authUserSelectAll(data) {
  return request({
    url: '/distribution/roleDistr/authUser/selectAll',
    method: 'put',
    params: data
  })
}

// 根据角色ID查询部门树结构
export function deptTreeSelect(roleId) {
  return request({
    url: '/distribution/roleDistr/deptTree/' + roleId,
    method: 'get'
  })
}
